package com.atguigu.oss.controller;

import com.atguigu.common.R;
import com.atguigu.oss.service.OssService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/eduoss/oss")
//@CrossOrigin
public class OssController {

    @Autowired
    private OssService ossService;

    //上传头像的方法
    @PostMapping("uploadFileOss")
    public R uploadFileOss(MultipartFile file) {
        //1 获取到上传过来文件  MultipartFile
        //<input type="file" name="file"/>

        //上传到阿里云oss
        //返回上传之后文件在阿里云oss地址
        String url = ossService.uploadFile(file);

        return R.ok().data("url",url);
    }

}
